package com.ruoyi.web.controller.webs.ky450;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ky450.domain.TargetCategory;
import com.ruoyi.ky450.service.ITargetCategoryService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 目标类别Controller
 *
 * @author ruoyi
 * @date 2025-01-16
 */
@RestController
@RequestMapping("/webs/targetCategory")
public class TargetCategoryController extends BaseController
{
    @Autowired
    private ITargetCategoryService targetCategoryService;

    /**
     * 查询目标类别列表
     */
    //@PreAuthorize("@ss.hasPermi('system:category:list')")
    @GetMapping("/list")
    public TableDataInfo list(TargetCategory targetCategory)
    {
        startPage();
        List<TargetCategory> list = targetCategoryService.selectTargetCategoryList(targetCategory);
        return getDataTable(list);
    }

    /**
     * 导出目标类别列表
     */
    //@PreAuthorize("@ss.hasPermi('system:category:export')")
    //@Log(title = "目标类别", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TargetCategory targetCategory)
    {
        List<TargetCategory> list = targetCategoryService.selectTargetCategoryList(targetCategory);
        ExcelUtil<TargetCategory> util = new ExcelUtil<TargetCategory>(TargetCategory.class);
        util.exportExcel(response, list, "目标类别数据");
    }

    /**
     * 获取目标类别详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(targetCategoryService.selectTargetCategoryById(id));
    }

    /**
     * 新增目标类别
     */
    //@PreAuthorize("@ss.hasPermi('system:category:add')")
    //@Log(title = "目标类别", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TargetCategory targetCategory)
    {
        return toAjax(targetCategoryService.insertTargetCategory(targetCategory));
    }

    /**
     * 修改目标类别
     */
    //@PreAuthorize("@ss.hasPermi('system:category:edit')")
    //@Log(title = "目标类别", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TargetCategory targetCategory)
    {
        return toAjax(targetCategoryService.updateTargetCategory(targetCategory));
    }

    /**
     * 删除目标类别
     */
    //@PreAuthorize("@ss.hasPermi('system:category:remove')")
    //@Log(title = "目标类别", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(targetCategoryService.deleteTargetCategoryByIds(ids));
    }
}
